<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>机构管理</title>
<!--  	<meta name="decorator" content="default"/>  -->
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<style type="text/css">
		.jqGrid_wrapper{padding:0;margin-top:2px;}
		
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			initGrid();//初始化表格
		});

	    /*初始化表格*/
	    function initGrid(){
	    	height=defaultHeight>600?(defaultHeight*0.76):(defaultHeight*0.665);
			if(isIE)height=height-5;
	    	$("#jqGrid").jqGrid({
                url: '${ctxAdmin}/sys/office/loadData?id=${id}',
                mtype: "POST",
                datatype: "json",
                responsive:true,
                page: 1,
                colModel: [
					{ label: 'id', name: 'id', key: true, hidden:true},     
                    { label: '机构名称',name: 'name',index: 'a.name',width: 150},
                    { label: '所属区域', name: 'area.name',index: 'ar.name',width:80},
                    { label: '机构编号', name: 'code',index:'a.code',width: 80},
                    { label: '备注', name: 'remarks',index:'a.remarks', width: 90 }, 
                    {label:'操作',name:'cz',search:false,sortable:false,title:false,formatter:czFmt,width:100,align: 'center'}
                ],
				viewrecords: true,
                height: height,
                rowNum: 10,
                rowList:[10,20,30],
                loadonce:false,
                multiselect: true, // 显示多选复选框
                autowidth: true,
                pager: "#jqGridPager"
            });
			$('#jqGrid').jqGrid('navGrid','#jqGridPager',{edit:false,add:false,del:false,search:false});
			$(window).bind("resize",function(){var width=$(".jqGrid_wrapper").width();$("#jqGrid").setGridWidth(width);});
	    }

	    function czFmt(c,o,r){
			var res='';
			var id=r.id;
			
			<shiro:hasPermission name="sys:office:edit">
			var addChild='<a class="btn btn-success btn-sm" href="${ctxAdmin}/sys/office/form?parent.id='+id+'">添加下级</a>';
			var edit ='<a class="btn btn-success btn-sm" href="${ctxAdmin}/sys/office/form?id='+id+'">修改</a>&nbsp;';
			var del = '<a class="btn btn-danger btn-sm" href="javascript:void(0)" onclick="deleteData(\''+id+'\')">删除</a>&nbsp;';
			res=edit+del+addChild;
			</shiro:hasPermission>
			return res;
		}

		function deleteData(id){
			
			confirmx('你确定要删除此数据吗？',null,function(){
					$.ajax({
					url:'${ctxAdmin}/sys/office/delete',
					type:'post',
					dataType:'json',
					data:{id:id},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});}		
			);
			
			
		}

		function deleteDataBatch(ids){
			var _ids=$('#jqGrid').jqGrid('getGridParam','selarrrow');
			if(_ids.length==0){
			layer.msg("请选择要操作的行！");
			return
			}
			var ids = _ids.join(",");
			
			confirmx('你确定要删除此数据吗？',null,function(){
					$.ajax({
					url:'${ctxAdmin}/sys/office/delete',
					type:'post',
					dataType:'json',
					data:{id:ids},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});}		
			);
									
			}

		$(function() {
			$('#btnSubmit').click(function() {
				var name = $("#name").val();
				var areaName = $("#areaName").val();
				var type = $("#type").val();
				$('#jqGrid').jqGrid('setGridParam', {
					datatype : 'json',
					postData : {
						'name' : name,
						'areaName' : areaName,
						'type':type
					}
				}).trigger("reloadGrid");
			});

		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctxAdmin}/sys/office/list">机构列表</a></li>
	</ul>
	
	<div class="jqGrid_wrapper" >
		<div class="search_row">
		   <form id="myForm">
			<label class="col-sm-1">机构名称：</label>
			<div class="col-sm-2">
				<input id="name" name="name" type="text"
					class="form-control ipt-search" />
			</div>
			<label class="col-sm-1">所属区域：</label>
			<div class="col-sm-2">
				<input id="areaName" name="areaName" type="text"
					class="form-control ipt-search" />
			</div>
			<div class="col-sm-search" >
			&nbsp;<input id="btnSubmit" class="btn btn-sm btn-success" type="button" value="查询" />
			&nbsp; <input id="btnReset" class="btn btn-sm btn-danger" type="button" value="重 置" />
			<shiro:hasPermission name="sys:office:edit">
			 &nbsp;<input id="btnDelete" class="btn btn-sm btn-danger" type="button" onclick="deleteDataBatch()" value="批量删除" />
			</shiro:hasPermission>
			</div>
			</form>
		</div>
		<div class="search_row_split"></div>
		 <table id="jqGrid"></table>
		 <div id="jqGridPager"></div>
	</div>
	
</body>
</html>